<?php
// +----------------------------------------------------------------------
// | title: 标题注释
// +----------------------------------------------------------------------
// | Author: TZ.Leong
// +----------------------------------------------------------------------
// | Date: 2019/7/15 11:08
// +----------------------------------------------------------------------

namespace app\single\controller;

use cmf\lib\Sign;
use think\facade\Request;

class ApiController
{
    //请求ip
    public $ip;
    //请求的参数
    public $postData;

    public function _empty()
    {
        //初始化获取参数
        $this->postData = Request::param();
        $this->ip = Request::ip();
        //检测请求权限ip
        if(checkIpRight($this->ip,config('api_ip_config'))){
            //验证秘钥sign
            if(Sign::validateSign($this->postData, $this->postData["sign"], config("secure.".GAME_NAME.'_key.TASK'))){
                //接口超时返回-2,暂定5分钟
                if(abs(time() - $this->postData['time']) < 60 * 5) {
                    //实例化计划任务文件
                    $className = "\\app\\single\\api\\" . Request::action(true);
                    $class = new $className();
                    $returnData = $class->run($this->postData);
                }else{
                    $returnData = array('ret' => -3,'msg' => '此次请求已超时：'.print_r($this->postData,true));
                }
            }else{
                $returnData = array('ret' => -2,'msg' => '密钥验证失败：'.Sign::$newSign.print_r($this->postData,true));
            }
        }else{
            $returnData = array('ret' => IP_DENIED,'msg' => $this->ip.'无权访问');
        }
        echo gzcompress(json_encode($returnData),8);
        exit;
    }
}